(function () {
    app
        .controller('calendarCtrl', ['$rootScope', '$scope', 'RESTService', function ($rootScope, $scope, RESTService) {
            $rootScope.selecInd = 3;
            $rootScope.showTabs = true;
            $scope.$on("$destroy", function () {
                $rootScope.showTabs = false;
            });

            $scope.calendars = {
                0:{
                    key:'yesterday',
                    heading:'昨天',
                    items:{}
                },
                1:{
                    key:'today',
                    heading:'今天',
                    items:{}
                },
                2:{
                    key:'tomorrow',
                    heading:'明天',
                    items:{}
                },
                3:{
                    key:'thisweek',
                    heading:'本周',
                    items:{}
                },
                4:{
                    key:'nextweek',
                    heading:'下周',
                    items:{}
                }
            };

            $scope._mode = '';
            $scope._key = '';
            $scope._ind = '';

            $scope.changeMode = function(mode){
                $scope._mode = mode;
                $scope.getCalendars($scope._key, $scope._ind);
            }

            $scope.getCalendars = function(key, ind){
                $scope._key = key;
                $scope._ind = ind;
                RESTService.getResponse('/rest/calendar/getCalendars?date=' + $scope._key + '&mode=' + $scope._mode).then(function(res){
                    $scope.calendars[ind].items = res.data;
                    console.log('calendars---', $scope.calendars, $scope._mode, $scope._key, $scope._ind);
                });
            }

        }])
})();